package com.erp.mclass;

import android.content.Context;
import android.util.Log;

import androidx.annotation.Keep;

import com.erp.Myapp;
import com.taobao.sophix.PatchStatus;
import com.taobao.sophix.SophixApplication;
import com.taobao.sophix.SophixEntry;
import com.taobao.sophix.SophixManager;
import com.taobao.sophix.listener.PatchLoadStatusListener;

/**
 * Created by Administrator on 2018/11/5/005.
 * 作者：刘洋
 */
public class SophixStubApplication extends SophixApplication {
    private final String TAG = "SophixStubApplication";
    // 此处SophixEntry应指定真正的Application，并且保证RealApplicationStub类名不被混淆。
    @Keep
    @SophixEntry(Myapp.class)
    static class RealApplicationStub {}
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//         如果需要使用MultiDex，需要在此处调用。
//         MultiDex.install(this);
        initSophix();
    }

    private void initSophix() {
        String appVersion = "1.4.42";
        try {
            appVersion = this.getPackageManager()
                    .getPackageInfo(this.getPackageName(), 0)
                    .versionName;
        } catch (Exception e) {
        }
        final SophixManager instance = SophixManager.getInstance();
        String rsa = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDOr2rZ/CQkWoAkLVm4/8H/DQ4oWIIZytJtk3XVwKPVudMUfF4uKgS6Ym4+MwFpoA/LNuUYMcI9dTc/G6TV5m22tCdyiJXoySLahFxxSw3DVK0apk3TbJwt++Ia2AlsG9pPsxBksWwIPNRg5k3NU5mUFSsqChAlVl1AYVR/6E1Ux+uahKkF2l5Xk+olU6PModt5hF4738LF/GFxd9Be7xnVzD73GXw6WB6fPDaKD042gfvhjMe2NX3RZDh2hpHxluEuL9Uh81Cf+sYCeOO+nZiVnXOeHY/aWknVEfpldswSiBMnzFAC/zMIKx6BCTh4ene5LgOcgSjXamzfjSWEUQHJAgMBAAECggEBAKw+U/XFwvjo0tFTWepqeelrn9jPqdyEwki/EvxHxkFe0yHHY1Vlfvs0/FqpdwvncEISRWmcThuZi6j0CLKZjeUszZMNcKDGvl0M4V0pBxc5gekrnsALSzynJQ7p6zBFJfI1b/v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instance.setContext(this)
                .setAppVersion(appVersion)
                .setSecretMetaData("23596523-1", "262de012cfb59b6dbd0cd4ec453596f6", rsa)
                .setEnableDebug(true)
                .setEnableFullLog()
                .setPatchLoadStatusStub(new PatchLoadStatusListener() {
                    @Override
                    public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) {
                        if (code == PatchStatus.CODE_LOAD_SUCCESS) {
                            Log.i(TAG, "sophix load patch success!");
                        } else if (code == PatchStatus.CODE_LOAD_RELAUNCH) {
                            Log.i(TAG, "sophix preload patch success. restart app to make effect.");
                            // 如果需要在后台重启，建议此处用SharePreference保存状态。
                            SophixManager.getInstance().killProcessSafely();
//                            Myapp.editor.putBoolean("Sophix", true).commit();

//                            Intent intent1 = new Intent();
//                            intent1.setAction(Contacts.BORADCAST_ACTION_SOPHIX);
//                            getApplicationContext().sendBroadcast(intent1);

                        }
                    }
                }).initialize();
    }
}